package es.castorm.business.customer.internal.config;

import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.metadata.ClassMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import es.castorm.arch.data.config.EnableJpa;
import es.castorm.arch.logging.config.EnableTraceLogging;
import es.castorm.business.customer.CustomerDTO;
import es.castorm.business.customer.internal.Customer;

//@EnableValidation
@EnableTraceLogging
@EnableTransactionManagement
@EnableJpa("es.castorm.business.customer.internal")
@EnableJpaRepositories("es.castorm.business.customer.internal")
@ComponentScan(basePackages = "es.castorm.business.customer.internal", excludeFilters = @Filter(type = FilterType.ANNOTATION, value = Configuration.class))
@Configuration
@Import(CustomerMapping.class)
public class CustomerConfig {

	@Autowired
	MapperFactory factory;

	@Bean
	public ClassMap<Customer, CustomerDTO> customerClassMap() {
		return factory.classMap(Customer.class, CustomerDTO.class).byDefault().toClassMap();
	}
}
